package Serializable_12;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Logon implements Serializable {
	private static final long serialVersionUID = 5246892086399825914L;
	
	private String date;
	private String userName;
	private transient String password;
	
	public Logon(String name, String pwd, String date) {
		this.userName = name;
		this.password = pwd;
		this.date = date;
	}
	
	public String toString() {
		return "logon info : \n username : " + userName +
				"\n date: " + date + "\n passowrd : " + password;
	}
	
	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException, InterruptedException {
		SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
		
		Logon a = new Logon("Tom", "tomPwd", dateFormat.format(new Date()));
		System.out.println("logon a = " + a);
		
		ObjectOutputStream out = new ObjectOutputStream(
				new FileOutputStream("Logon.out"));
		out.writeObject(a);
		out.close();
		
		Thread.sleep(5000);
		System.out.println("\nRecovering object at \n date: " + dateFormat.format(new Date()) + "\n");
		
		ObjectInputStream in = new ObjectInputStream(
				new FileInputStream("Logon.out"));
		a = (Logon) in.readObject();
		System.out.println("logon a = " + a);
	}

}
